#include "mystack.h"

int main(int argc, char const *argv[])
{
	MyStack<char> *pStack = new MyStack<char>(30);
	MyStack<char> *pNeedStack = new MyStack<char>(30);

	char str[] = "[[(xyyyyxxxx)]]";
	char currentNeed = 0;

	for (int i = 0; i < strlen(str); ++i)
	{
		if (str[i] != currentNeed)
		{
			switch(str[i]) 
			{
				case '[':
					pStack->push(str[i]);
					if (currentNeed != 0) 
					{
						pNeedStack->push(currentNeed);
					}

					currentNeed = ']';

					break;
				case '(':
					pStack->push(str[i]);
					if (currentNeed != 0) 
					{
						pNeedStack->push(currentNeed);
					}
					currentNeed = ')';
					break;
				default:
					std::cout << str[i] << "不匹配" << std::endl;
					break;

			}
		} else {
				char elem;
				pStack->pop(elem);
				if (!pNeedStack->pop(currentNeed))
				{
					currentNeed = 0;
				}
		}
	}

	if (pStack->stackEmpty())
	{
		std::cout << "匹配" << std::endl;
	} else {
		std::cout << "不匹配" << std::endl;
	}


	delete pStack;
	pStack = NULL;

	delete pNeedStack;
	pNeedStack = NULL;
	return 0;
}